﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CUMTConnect
{
	/// <summary>
	/// WIFIAddedForm.xaml 的交互逻辑
	/// </summary>
	public partial class WIFIAddedForm : Window
	{
		/**
		 * this member carry selected SSID to MainWindow
		 */
		public String SSID { get; set; }
		public WIFIAddedForm()
		{
			InitializeComponent();
			ScanSSID();
		}

		/**
		 * Add SSID to ListView Component
		 * when 2.4GHz and 5GHz use same name, will remove duplicate automatically
		 * also it would not add existed item
		 */
		private void AddToWIFIList(String SSID)
		{
			if (this.WIFIList.Items.Contains(SSID) || SSID == "")
			{
				return;
			}
			else
			{
				this.WIFIList.Items.Add(SSID);
			}
		}

		/**
		 * Scan the WIFI List now which could be scanned
		 * it would fresh ListView component's items
		 */
		private void ScanSSID()
		{
			this.WIFIList.Items.Clear();
			String[] SSIDList = WIFI.ScanSSID().Split(";".ToCharArray());
			foreach(var SSID in SSIDList)
			{
				this.AddToWIFIList(SSID);
			}
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			this.SSID = this.WIFIList.SelectedItem.ToString();
			this.Close();
		}

		private void Button_Click_1(object sender, RoutedEventArgs e)
		{
			ScanSSID();
		}

		private void Button_Click_2(object sender, RoutedEventArgs e)
		{
			this.SSID = "";
			this.Close();
		}
	}
}
